//
// Created by wll on 2021/10/11.
//

#include <iostream>
#include <boost/algorithm/hex.hpp>
#include <boost/uuid/sha1.hpp>
#include <fstream>

using namespace std;

bool sha1(const string& file_name, string& sha1_str)
{
    ifstream input_stream(file_name);
    if (!input_stream) return false;

    boost::uuids::detail::sha1 sha;
    unsigned int digest[5];
    char c;
    while(input_stream.get(c))
    {
        sha.process_byte(c);
    }
    sha.get_digest(digest);
    sha1_str.clear();
    boost::algorithm::hex((char*)digest,(char*)digest+sizeof(boost::uuids::detail::sha1::digest_type), std::back_inserter(sha1_str));

    return true;
}
